package Derivation;

import Basics.*;

public class SemiNaive 
{
	Program p;
	
	ParseResultsBottomUp parser;
	

	
	public SemiNaive (Rule ... irs)
	{
		this.p = new Program(irs);
		this.parser = new ParseResultsBottomUp(irs);
	}
	
	
	public SemiNaive (Program irs)
	{
		this.p = irs;
		this.parser = new ParseResultsBottomUp(this.p);
	}
	

	
	public Program getP() 
	{
		return p;
	}


	public void setP(Program p) 
	{
		this.p = p;
	}


	
	public ParseResultsBottomUp getParser() 
	{
		return parser;
	}

	

	public void setHelper(ParseResultsBottomUp iparser)
	{
		this.parser = iparser;
	}


	/*************************************************************************************************************/
	/** Title: SemiNaiveIteration																				
	/** Description: performs one iteration of semi-naive algorithm 			
	/*************************************************************************************************************/
	
	public boolean SemiNaiveIteration (boolean forIntersection)
	{
		parser.ParseResults(forIntersection);
		parser.UpdateDB();
		boolean retVal = parser.isFixedPoint();
		//DEBUG
		/*System.out.println("atoms added at this step: " + parser.getAddedInstAtoms());
		System.out.println("provenance at this step: " + parser.getProvenance());*/
		//System.out.println("prov2 at this step: " + parser.constantsProgram);
		
		parser.Reset();
		return retVal;
	}
	
	
	
	
	/*************************************************************************************************************/
	/** Title: Run																			
	/** Description: SemiNaiveAlgorithm 			
	/*************************************************************************************************************/
	
	public void Run (boolean forIntersection)
	{
		while (false == SemiNaiveIteration(forIntersection));
	}
	
}
